package com.aigc.sclassroom.service.impl;

import com.aigc.sclassroom.mapper.SurveyMapper;
import com.aigc.sclassroom.pojo.Survey;
import com.aigc.sclassroom.service.SurveyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SurveyServiceImpl implements SurveyService {
    @Autowired
    private SurveyMapper surveyMapper;
    @Override
    public void add(String surveyName, Long courseManageId) {
        surveyMapper.add(surveyName,courseManageId);
    }


    @Override
    public List<Survey> listAll(Long courseManageId) {
        List<Survey> ls = surveyMapper.selectSurveyByCourseManageId(courseManageId);
        for (int i =0;i<ls.size();i++){
            Survey survey = ls.get(i);
            survey.setSum(surveyMapper.selectSum(courseManageId));
            Long surveyId = survey.getSurveyId();
            survey.setSubmit_count(surveyMapper.selectSubmitCount(surveyId,courseManageId));
        }
        return ls;
    }
}

